package com.hx.company.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

import org.junit.Test;

public class PicToString {
	@Test
	public  void readBlob() throws Exception {
	 		String path="C:/Users/PC/Desktop/qq.jpg";
	 		File file = new File(path);
	 		
	 		InputStream is = new FileInputStream(file);
	 		File destFile = new File("C:/Users/PC/Desktop","a.jpg");
	 		OutputStream os = new FileOutputStream(destFile);
	 		byte[] buffer = new byte[1024];
	 		int length = 0 ;
	 		while((length = is.read(buffer))>0){
	 			os.write(buffer, 0, length);
	 		}
	 		is.close();
	 		os.close();
	 		
	 		
	           
	}
	
	
	
	@Test
	public String inputStream2String(InputStream is) throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(is));
		StringBuffer buffer=new StringBuffer();
		String line="";
		while((line=in.readLine())!=null){
			buffer.append(line);
		}
	return buffer.toString(); 
	}
          
	

}
